Accurate time breakdown: cap suspensions + union parallel spans (+ parallelism insight)#10
Open
wan-huiyan wants to merge 4 commits into
Open
Accurate time breakdown: cap suspensions + union parallel spans (+ parallelism insight)#10wan-huiyan wants to merge 4 commits into
wan-huiyan wants to merge 4 commits into
Conversation
…unted as thinking (#4) Only the assistant-end→user gap was capped by IDLE_THRESHOLD_MS. The user→assistant and tool_result→assistant gaps (both → claudeThink) were uncapped, so any long pause landing mid-turn (overnight gap after a tool result, credit stall, remote-control handoff) was reported as hours of "Claude thinking." Add THINK_CAP_MS (10 min) and an emitThink() helper that caps the thinking slice and books the remainder as humanAway. On a real 16h session with overnight gaps this moves ~9h out of "thinking" (11h34m → 2h35m) into away time. +3 unit tests; all 90 pass; tsc clean.
…t sum (#3) computeEnhancedStats emitted one segment per tool/agent and summed their durations. When tools or subagents are fanned out in a single assistant turn (e.g. a 5-agent review panel, or parallel Read/Bash calls), those segments overlap in wall-clock time, so summing double-counts the concurrency — the 'Subagents' bar reported cumulative agent-seconds, not real elapsed time, and the active-time percentages could sum to >100% (e.g. 109%). Aggregate toolExec and subagent by wall-clock interval UNION instead: - subagent = time with >=1 subagent open - toolExec = busy-with-a-tool time NOT already counted as subagent (subagent wins the rare cross-kind overlap, e.g. Agent + Bash in one turn) claudeThink / planning / humanWait / humanAway are emitted as sequential, non-overlapping slices and are still summed (unchanged). On a fan-out-heavy session this dropped reported subagent time from ~53m (sum of 19 overlapping agents) to ~38m (true elapsed), and the breakdown now sums to ~100% instead of 109%. The per-call 'Tools' latency table (avg/p50/p95) is computed separately and is intentionally unchanged. Tests: 3 cases (parallel agents → union not sum; parallel non-agent tools → union; sequential agents still add up). 90/90 tests pass.
Time accounting must aggregate possibly-overlapping phase spans by wall-clock UNION, not SUM — parallel tool/subagent spans (two tool_use in one assistant message share the same start) overlap, so a naive sum overcounts and can exceed the session's wall-clock. This adds a regression guard: - union(enhancedSegments) ≤ (max endTime − min startTime), always - a parallel-tools scenario where naiveSum > span (proves the overlap is real, so the invariant is non-vacuous) while union ≤ span - each segment is a valid non-negative interval (endTime ≥ startTime, durationMs === endTime − startTime) Pure test addition (no src change). Full suite 89 passing; tsc clean. Came out of an independent wall/active/away recompute that used exactly this union-vs-sum cross-check to reconcile against the live tool. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
) Surfaces the value of fanning out: the subagent phase is aggregated by wall-clock union (correct elapsed time), but sum−union = time saved by running agents concurrently and sum/union = effective concurrency. Adds an Insights line shown only when ≥2 subagents actually overlapped (saved >1s), so sequential sessions get no spurious line. Exports unionMs from analyzer for reuse. +3 formatter tests. 102 pass; tsc clean.
This was referenced May 29, 2026
Closed
Author
|
Hi @dioptx, thank you so much for cctime — it's genuinely become part of my daily Claude Code workflow ❤️ I found a few accuracy issues + small improvements and (apologies for the churn 🙈) opened a bunch of PRs while iterating. I've now consolidated everything into 3 focused PRs to keep review manageable:
Each is self-contained with tests + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three related time-accounting changes (grouped to keep review manageable and avoid pairwise conflicts — all touch
analyzer.ts/analyzer.test.ts):user→assistantandtool_result→assistantgaps were uncapped, so a mid-turn suspension (overnight pause / credit stall / handoff) read as hours of "thinking." Excess →humanAway. On a 16h session this moved ~9h out of thinking.⚡ Parallel subagents: 5 ran in 38m wall (53m of work · 1.4× concurrent · saved 15m vs sequential), shown only on real overlap.Plus a
union(segments) ≤ wall-clock spaninvariant test.All self-contained; 98 tests pass,
tscclean. Supersedes the separate #6/#7 (consolidated here).🤖 Generated with Claude Code